<?php
class ml_model_dbCollectionComment extends Lib_datamodel_db
{

    public function __construct()
    {
        $db_config = ml_factory::load_standard_conf('db');
        parent::__construct('collection_comment' , $db_config['collection_comment']);
    }

    public function insert_comment($rid,$name,$uid,$cid,$comment){
        $o_uid=ml_tool_resid::resid2uid($rid);
        if(!$this->init_db($o_uid, self::DB_MASTER))
        return false;

        $arrInsert = array(
            'rid' => $rid,
            'col_id' => $cid,
            'ctime' => date('Y-m-d H:i:s', time()),
            'status' => '1',
            'cip' => Tool_ip::get_real_ip(),
            'comment'=>$comment,
            'uid'=>$uid,
            'name'=>$name

        );

        return $this->insert($arrInsert);

    }

    public function getComment($rid,$begin=0,$count=10){
        if(!$this->init_db($uid, self::DB_SLAVE))
        return false;
        $begin=$this->escape($begin);
        $count=$this->escape($count);
        $where=" where `rid`='$rid' and `status`='1' order by `ctime` desc limit $begin,$count";
        $sql="select `name` as `albumName`,`comment`,`ctime`,`uid`,`col_id`  from `$this->table` $where";
        $rs=$this->fetch($sql);

        return $rs?$this->_data:false;
    }
    public function getTotal($rid){
        $o_uid=ml_tool_resid::resid2uid($rid);
        if(!$this->init_db($o_uid, self::DB_SLAVE))
        return false;
        $sql="select count(*) as `num`  from `$this->table` where `rid`='$rid' and `status`='1'";
        $rs=$this->fetch($sql);
        return $rs?$this->_data[0]:false;

    }
    public function delComment($rid,$col_id,$uid){
        $o_uid=ml_tool_resid::resid2uid($rid);
        if(!$this->init_db($o_uid, self::DB_MASTER))
        return false;
        return $this->update(array('status' => 9), "`rid`='$rid' and `col_id`='$col_id' and `uid`='$uid'", 1);
    }

}

?>